<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    onkeypress = function (){
        const xhr = new XMLHttpRequest()
        // 超时
        xhr.timeout = 2000
        xhr.ontimeout = function (){
            alert('timeout!!')
        }
        // 网络异常
        xhr.onerror = function (){
            alert('error')
        }

        xhr.open('post','http://127.0.0.1:8000/network')
        xhr.send()
        xhr.onreadystatechange = function (){
            if (xhr.readyState === 4){
                if (xhr.status >= 200 && xhr.status <300){
                    console.log(xhr.response)
                }
            }
        }
    }
</script>
</body>
</html>
